﻿@model mvcForum.Web.ViewModels.SearchViewModel
@using mvcForum.Web.Extensions;
@using mvcForum.Web.Helpers;
@{
	ViewBag.Title = ForumHelper.GetString("Title", null, "mvcForum.Web.Search");
	Layout = "~/areas/forum/views/shared/forumlayout.cshtml";
}
@Html.Partial("Breadcrumb", new Dictionary<String, String>())
<a name="start_here"></a>
<div id="page-body">
	<div id="content-start"> </div>
@if (Model.Results != null && Model.Results.Any()) {
		<h2>@ForumHelper.GetHtmlString("FoundTitle", "mvcForum.Web.Search", new { Query = Model.Query, Results = Model.Results.Count() })</h2>
		<p>@Html.ActionLink(ForumHelper.GetLinkText("BackToAdvanced", null, "mvcForum.Web.Search"), "Index", "Search", new { area = "forum" }, new { @class = "left", title = ForumHelper.GetString("Search.BackToAdvancedTitle") })</p>
		<div class="forumbg">
			<div class="block-border block-block">
				<div class="block-content">
					<ul class="topiclist">
						<li class="header">
							<dl class="icon">
								<dt>Topics</dt>
								<dd class="posts">Replies</dd>
								<dd class="views">Views</dd>
								<dd class="lastpost"><span>Last post</span></dd>
							</dl>
						</li>
					</ul>
		@foreach (var result in Model.Results) {
	  var iconName = String.Empty;
	  if (result.Sticky) {
		  iconName += "sticky";
	  }
	  else if (result.Announcement) {
		  iconName += "announcement";
	  }
	  else {
		  iconName += "topic";
	  }
	  if (result.HasUnread) {
		  iconName += "_unread";
	  }
	  else {
		  iconName += "_read";
	  }
	  if (result.Locked) {
		  iconName += "_locked";
	  }
	  iconName += ".gif";
					<ul class="topiclist topics">
						<li class="row bg1">
							<dl style="background-image: url(@Url.ForumImage(iconName)); background-repeat: no-repeat;" class="icon">
								<dt>
									@Html.TopicLink(result.Id, result.Title, new { @class = "topictitle" })
									<br />
									@ForumHelper.GetHtmlString("Topic.LastPost", new object[] { result.Author.Wrap("<a href=\"" + Url.RouteUrl("ShowProfile", new RouteValueDictionary { { "id", result.AuthorId }, { "name", result.Author.ToSlug() } }) + "\">{#}</a>"), result.Posted })
									@*TODO: in <a href="./viewforum.php?style=12&amp;f=2">Your first forum</a>*@
								</dt>
									<dd class="posts">@result.MessageCount</dd>
									<dd class="views">@result.Views</dd>
									<dd class="lastpost">@Html.Partial("LastMessagePartial", result)</dd>
								</dl>
							</li>		
						</ul>
  }
						<div class="block-footer"> </div>
					</div>
				</div>
			</div>
}
else {
	<h2 class="solo">@ForumHelper.GetHtmlString("Search.Headline")</h2>
	if (Model.Results != null) {
		@ForumHelper.GetHtmlString("NoResults", "mvcForum.Web.Search", new { Query = Model.Query });
	}
	using (Html.BeginForm("Index", "Search", FormMethod.Post, new Dictionary<String, Object> { { "name", "MainSearchForum" } })) {
		<div class="panel">
			<div class="block-border block-block">
				<div class="block-content">
					<h3>@ForumHelper.GetHtmlString("QuerySubHeading", "mvcForum.Web.Search", null)</h3>
					<fieldset>
						<dl>
							<dt>@Html.LabelFor(x => x.Query)</dt>
							<dd>@Html.TextBoxFor(x => x.Query, new { @class = "inputbox" })</dd>
						</dl>
					</fieldset>
					<div class="block-footer"></div>
				</div>
			</div>
		</div>
 		<div class="panel bg2">
			<div class="block-border block-block">
				<div class="block-content">
					<h3>@ForumHelper.GetHtmlString("OptionsSubHeading", "mvcForum.Web.Search", null)</h3>
					<fieldset>
						<dl>
							<dt>@Html.LabelFor(x => x.Forums)</dt>
							<dd>@ForumHelper.GetForumMultiSelect("Forums", Model.Forums, new Dictionary<String, Object> { { "size", 8 } })</dd>
						</dl>
					</fieldset>
					<div class="block-footer"></div>
				</div>
			</div>
		</div>
		<div class="panel bg3">
			<div class="block-border block-block">
				<div class="block-content">
					<fieldset class="submit-buttons">
						<input class="button2" type="reset" name="reset" value="@ForumHelper.GetString("ResetButton", null, "mvcForum.Web.Search")" />
						<input class="button1" type="submit" value="@ForumHelper.GetString("SearchButton", null, "mvcForum.Web.Search")" name="submit" />
					</fieldset>
					<div class="block-footer"></div>
				</div>
			</div>
		</div>
	}
}
</div>
